package cn.com.haopy.yue.ai.db.service.hos.impl;

import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskTopicOptions;
import cn.com.haopy.yue.ai.db.mapper.arisk.AIRiskTopicOptionsMapper;
import cn.com.haopy.yue.ai.db.service.BaseServiceImpl;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskTopicOptionsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Description: TODO
 * @Author DuTao
 * @Date 2025/3/26 10:11
 */
@Service
public class AIRiskTopicOptionsServiceImpl extends BaseServiceImpl<AIRiskTopicOptionsMapper, AIRiskTopicOptions> implements AIRiskTopicOptionsService {
    @Override
    public List<AIRiskTopicOptions> listByTopicId(Integer topicId) {
        LambdaQueryWrapper<AIRiskTopicOptions> queryWrapper = new LambdaQueryWrapper<>();
        if (Objects.nonNull(topicId)) {
            queryWrapper.eq(AIRiskTopicOptions::getTopicId, topicId);
        }
        queryWrapper.orderByAsc(AIRiskTopicOptions::getSortIndex);

        List<AIRiskTopicOptions> resultList = super.list(queryWrapper);
        if (CollectionUtils.isEmpty(resultList)) {
            return new ArrayList<AIRiskTopicOptions>();
        } else {
            return resultList;
        }
    }

    @Override
    public List<AIRiskTopicOptions> getByCondition(Integer topicId, String option) {
        QueryWrapper<AIRiskTopicOptions> queryWrapper = new QueryWrapper<>();
        if (Objects.nonNull(topicId)) {
            queryWrapper.lambda().eq(AIRiskTopicOptions::getTopicId, topicId);
        }
        if (Objects.nonNull(option)) {
            queryWrapper.lambda().eq(AIRiskTopicOptions::getOptionName, option);
        }
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public int deleteByTopicId(Integer topicId) {
        QueryWrapper<AIRiskTopicOptions> queryWrapper = new QueryWrapper<>();
        if (Objects.nonNull(topicId)) {
            queryWrapper.lambda().eq(AIRiskTopicOptions::getTopicId, topicId);
        }
        return baseMapper.delete(queryWrapper);
    }

    @Override
    public List<AIRiskTopicOptions> getByTopicId(Integer topicId) {
        QueryWrapper<AIRiskTopicOptions> queryWrapper = new QueryWrapper<>();
        if (Objects.nonNull(topicId)) {
            queryWrapper.lambda().eq(AIRiskTopicOptions::getTopicId, topicId);
        }
        return baseMapper.selectList(queryWrapper);
    }
}
